import scrapy


class QidianSpider(scrapy.Spider):
  name = 'qidian'
  allowed_domains = ['www.qidian.com/rank/yuepiao']
  start_urls = ['http://www.qidian.com/rank/yuepiao/']

  def parse(self, response):
    names = response.xpath('//h4/a/text()').extract()
    authors = response.xpath('//p[@class="author"]/a[1]/text()').extract()
    print(names)
    print(authors)
    books = []
    for name, author in zip(names, authors):
      books.append({'name': name, 'author': author})
    return books
    # 如何提取books到文件？ scrapy crawl qidian -o books.json / books.csv
